using FluentNHibernate.Conventions;
using FluentNHibernate.Mapping;
using Tools.Common.Reflection;
using Webshop20.Domain.Catalog.Core;

namespace Webshop20.Infrastructure.Persistence.NH.AutoMappings.Conventions.Particular
{
    public class VisitorConventions : IReferenceConvention
    {
        public bool Accept(IManyToOnePart target)
        {
            return target.EntityType.Name == typeof (Visitor).Name;
        }

        public void Apply(IManyToOnePart target)
        {
            if (target.Property.Name == ReflectAbout<Visitor>.GetProperty(x => x.Cart).Name)
                target.Cascade.All();
        }
    }
}